﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace X13
{
    public static class Resources
    {
        public static Dictionary<string, Effect> FxLibaray;
        public static Effect MinefieldEffect { get {return FxLibaray["Minefield"]; } }
        public static Effect ProbeEffect { get { return FxLibaray["Probe"]; } }

        public static Dictionary<string, Texture2D> MinefieldTexturedLibary;
        public static Texture2D FenceTexture, MineSpiralTexture;

        public static Dictionary<MinfieldColourState, Color> MinefieldColourDictionary;
        public static Dictionary<ModelType, Model> MinefieldModels;
        public static Dictionary<string, SpriteFont> Fonts;
        public static Dictionary<string, string> FontLocations;

        //METHODS        
        public static void LoadData(Game game)
        {
            //Load in the Effects
            FxLibaray = new Dictionary<string, Effect>();
            FxLibaray.Add("Minefield", game.Content.Load<Effect>("gfx/minefield"));

            //The Models
            MinefieldModels = new Dictionary<ModelType, Model>();
            MinefieldModels.Add(ModelType.CellBase, LoadModel(game, MinefieldEffect, @"assets\cell"));
            MinefieldModels.Add(ModelType.CellFence, LoadModel(game, MinefieldEffect, @"assets\fence"));
            MinefieldModels.Add(ModelType.CellMineSpiral, LoadModel(game, MinefieldEffect, @"assets\minespiral"));

            //The Colours
            MinefieldColourDictionary = new Dictionary<MinfieldColourState, Color>();
            MinefieldColourDictionary.Add(MinfieldColourState.Red, Color.Red);
            MinefieldColourDictionary.Add(MinfieldColourState.Green, Color.Green);
            MinefieldColourDictionary.Add(MinfieldColourState.Yellow, Color.Yellow);

            //The Textures
            FenceTexture = game.Content.Load<Texture2D>(@"Graphics\uv\$fence");
            MineSpiralTexture = game.Content.Load<Texture2D>(@"Graphics\uv\$fence");

            MinefieldTexturedLibary = new Dictionary<string, Texture2D>();
            MinefieldTexturedLibary.Add("Dirt", game.Content.Load<Texture2D>(@"Graphics\uv\$celldirt"));
            MinefieldTexturedLibary.Add("Grass", game.Content.Load<Texture2D>(@"Graphics\uv\$cellgrass"));

            //Fonts
            Fonts = new Dictionary<string, SpriteFont>();
            Fonts.Add("Default", game.Content.Load<SpriteFont>("default"));

            FontLocations = new Dictionary<string, string>();
            FontLocations.Add("Default", "default");
        }

        public static Model LoadModel(Game game, Effect fx, string assetName)
        {
            Model newModel = game.Content.Load<Model>(assetName);

            foreach (ModelMesh mesh in newModel.Meshes)
                foreach (ModelMeshPart meshPart in mesh.MeshParts)
                    meshPart.Effect = fx.Clone();

            return newModel;
        }
    }

    public enum MinfieldColourState {
        Red = 1,
        Green = 2,
        Yellow =3,
    }
    public enum ModelType {
        CellBase = 1,
        CellFence,
        CellMineSpiral,
        MineProbe,
    }
}
